<!-- 工程会议管理 -->
<template>
  <base-breadcrumb :title="$route.meta.title">
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <!-- 搜索 -->
        <searchData
          :search-data="searchOption"
          @search="search"
        />
        <!-- 搜索 -->
        <a-card class="page-height-list">
          <!-- <title-name title="工程会议管理" /> -->
          <div class="table-operator">
            <a-button
              v-btnPermission="[{code:'seex_pm_051_add_02',ident:'prma_seex'},{code:'buco_pm_051_add_02',ident:'prma_buco'}]"
              type="primary"
              @click="handleAdd"
            >新增会议</a-button>
          </div>
          <div class="pub-table-select-count">
            <a-icon
              type="info-circle"
              theme="twoTone"
            />
            <span style="margin-right: 12px">总数量：<span class="totalNum">{{ totalSize }} 个</span>
            </span>
          </div>
          <list-table
            :defaultLoad="false"
            ref="table"
            size="default"
            rowKey="id"
            :columns="columns"
            :request="loadData"
            :alert="true"
            show-size-changer
            show-quick-jumper
            :page-keys="['pageNum', 'pageSize','total']"
            show-pagination="auto"
            :loadPage="{
              currentPage: 'pageNum',
              totalSize: 'total',
              data: 'list'
            }"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>

            <span
              slot="action"
              slot-scope="text, record"
            >
              <MoreButton>
                <!-- 会议详情 -->
                <template v-if="record.meetingStatus === '20'">
                  <a
                    v-btnPermission="[{code:'seex_pm_051_loo_03',ident:'prma_seex'},{code:'buco_pm_051_loo_03',ident:'prma_buco'}]"
                    @click="handleOperation(record, 'detail')"
                  >会议详情</a>
                </template>
                <template v-if="(record.meetingStatus === '30' || record.meetingStatus === '50')&&hideBuquBtn()">
                  <a @click="handleOperation(record, 'join')">进入会议</a>
                </template>
                <template v-if="record.meetingStatus === '40' || record.meetingStatus === '35'">
                  <a
                    v-btnPermission="[{code:'seex_pm_051_loo_01',ident:'prma_seex'},{code:'buco_pm_051_loo_01',ident:'prma_buco'}]"
                    @click="handleOperation(record, 'view')"
                  >查看会议</a>
                </template>
              </MoreButton>
            </span>
          </list-table>
        </a-card>
      </a-col>
    </a-row>
    <!-- <ApprovalDetails
      :title="'审批详情'"
      :tab1="tab1"
      :tab2="tab2"
      :business-id.sync="businessId"
      :visible="visibleApprove"
      @changeBusinessId="changeBusinessId"
      @cancel="visibleApprove = false"
      @confirm="visibleApprove = false"
    /> -->
  </base-breadcrumb>
</template>

<script>
import { searchOption, columns, mockdata } from './model.js'
import { getPageProjectCycleEarlyWarn } from '@/api/project/warning'
import training from '@/api/design/training'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'
// import Opera from './components/Opera.vue'
// import mixins from './mixins.js'
// import ApprovalDetails from './components/ApprovalDetails'
export default {
  name: 'warning',
  components: {
    PermissionTreeOrganization
    // Opera,
    // ApprovalDetails
  },
  // mixins: [mixins],
  data() {
    return {
      tab1: {
        label: '拟采取措施',
        status: true
      },
      tab2: {
        label: '验收记录',
        status: true
      },
      businessId: '',
      totalSize: 0,
      visibleApprove: false, // 审批toast
      // 收缩展开树
      collapsed: false,
      // 搜索选项
      searchOption,
      //组织架构选中项
      select: null,
      // 查询参数
      queryParam: {},
      columns,
      loadData: async (p) => {
        const obj = {}
        // if (!this.select) {
        //   return
        // }
        // 二级-分公司id
        if (this.select?.tageCode === 'BC') {
          obj.branchComId = this.select.orgId
        }
        // 三级-项目id
        if (this.select?.tageCode === 'PD') {
          obj.projectId = this.select.projectId
        }
        obj.qualityMeeting = 2
        let searchData = Object.assign(p, { param: { ...obj, ...this.queryParam } })
        console.log(searchData)
        let res = await training.getPageMeeting(searchData)
        if (res.code === 200) {
          this.totalSize = res.data.total
          return { code: 200, data: res.data.list, ...res.data }
        }
        return { code: 200, data: [], total: 0, pageNum: 0 }
        // return new Promise((resove, reject) => {
        //   setTimeout(() => {
        //     console.log(mockdata)
        //     resove({
        //       code: 200,
        //       currentPage: 0,
        //       totalSize: 3,
        //       data: mockdata
        //     })
        //   }, 3000)
        // })

        // return getPageProjectCycleEarlyWarn(searchData).then((res) => {
        //   console.log('getPageProjectCycleEarlyWarn', res)
        //   this.totalSize = res.data.total
        //   return res.data
        // })
      }
    }
  },

  computed: {},

  watch: {
    visibleApprove(val) {
      if (!val) {
        this.tab2.status = false
      }
    }
  },

  mounted() {
    // this.$store.commit('tabInfo/ADD_CACHE_PAGE', 'warning')
  },

  methods: {
    // 审批信息-点击验收记录 重构businessId  businessId=${businessId}_record
    changeBusinessId(businessId, cb) {
      cb(`${businessId}_record`)
    },
    // 审批信息
    approveHandler({ warnLevel, id }) {
      // 蓝色预警无“验收记录”流程
      if (Number(warnLevel) === 0) {
        this.tab2.status = false
      } else {
        this.tab2.status = true
      }
      this.visibleApprove = true
      this.businessId = id
    },
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      this.search()
    },
    // 新增预警
    handleAdd() {
      this.$router.push({
        path: '/project/meetings/edit',
        query: {
          typeId: 110
        }
      })
    },
    /**
     * @description: 会议操作
     * @param {object} record
     * @param {string} pageType
     * @return {void}
     */
    handleOperation(record, pageType) {
      this.$router.push({
        path: '/project/meetings/inputSummary',
        query: {
          id: record.id,
          meetingName: record.meetingName,
          pageType
        }
      })
    },
    search(val) {
      this.queryParam = {}
      console.log(val)
      if (val) {
        const { meetingName = '', meetingStatus = '', meetingType = '', startEndDateStart = '', startEndDateEnd = '', startEndDate = [] } = val

        if (meetingName !== '') {
          this.queryParam.meetingName = meetingName
        }
        if (meetingStatus !== '') {
          this.queryParam.meetingStatus = meetingStatus
        }
        if (meetingType !== '') {
          this.queryParam.meetingType = meetingType
        }
        if (startEndDateStart !== '' && startEndDate.length) {
          this.queryParam.startTime = startEndDateStart
        }
        if (startEndDateEnd !== '' && startEndDate.length) {
          this.queryParam.endTime = startEndDateEnd
        }
      }
      this.$refs.table.refresh(true)
    }
  }
}
</script>
<style lang='less' scoped>
</style>
